
#include "Core/Errors.h"

using namespace System;
using namespace NUnit::Framework;

namespace ttgLibTests
{
	[TestFixture]
	public ref class Errors
	{
		public:
			[Test]
			void SimpleError()
			{
				try
				{ throw ttgLib::LocalError("Av-av-avaf"); }
				catch (ttgLib::Error err)
				{ return; }
				Assert::Fail("Error wasn't catched");
			}

			[Test]
			void StlException()
			{
				try
				{ throw ttgLib::LocalError("Av-av-avaf"); }
				catch (std::exception &err)
				{ return; }
				Assert::Fail("Error wasn't catched");
			}

			[Test]
			void InnerErrors()
			{
				try
				{
					ttgLib::LocalError er1("Err1");
					ttgLib::LocalError er2("Err2", er1);
					ttgLib::LocalError er3("Err3", er2);
					throw ttgLib::LocalError("ErrGlobal", er3);
				}
				catch (ttgLib::Error err)
				{ Assert::AreEqual((int)err.GetInnerErrors().size(), 3, "Inner errors were ignored"); }
			}

			[Test]
			void DescriptionCheck()
			{
				try
				{ throw ttgLib::LocalError("ErrGlobal", "TestClass", "TestMethod"); }
				catch (std::exception &err)
				{ Assert::AreNotEqual((int)err.what(), NULL, "Description was ignored"); }
			}
	};
}
